#!/usr/bin/env bash
# 同步宝塔证书夹域名
# eg: linkCert.sh lj4.top
set -e
if [ $# -eq 0 ]; then
  echo "请输入域名"
  exit 1
fi
rootCert="/www/server/panel/vhost/cert/$1"
d=(/www/server/panel/vhost/cert/*.$1)
baseFolder="/www/server/panel/vhost/ssl/$1"
# 判断根域名
if [ -L $rootCert ]; then
  echo
else
  rm -rf $rootCert
  ln -s $baseFolder $rootCert
fi
# 判断泛域名
for i in "${d[@]}"; do
  [ -L $i ] && continue
  rm -rf $i
  ln -s $baseFolder $i
done
# 更新nginx配置
systemctl reload nginx.service
echo "操作结果$?"
